package com.zsc.common.web.handler;

import com.zsc.common.web.request.Request;
import com.zsc.common.web.request.SyncCostRequest;
import com.zsc.common.web.util.JsonUtils;
import com.zsc.common.web.util.MD5Util;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

/**
 * SyncCostServiceHandler.java是互动平台的同步消费记录到互动管理平台业务处理器抽象类。
 *
 * @author jason
 * @version 1.0 2017年3月19日
 */
@Service(value = "syncCostHandler")
@Scope("prototype")
public class SyncCostServiceHandler extends AbstractLvmServiceHandler {

    /**
     * 操作名
     */
    private static final String ACTION = "/handler/cost.ashx";

    /**
     * 互动管理平台的请求参数验证码秘钥
     */
    @Value(value = "${commons.lvm.check.key}")
    protected String checkKey;

    /**
     * 同步消费记录
     */
    private SyncCostRequest costRequest;

    @Override
    public String getInterfaceName() {
        return ACTION;
    }

    @Override
    public String getRequestData() {
        costRequest.setChksum(MD5Util.md5(costRequest.getUserId() + checkKey));
        Request<SyncCostRequest> request = new Request();
        request.setAction(ACTION);
        request.setParams(costRequest);
        return JsonUtils.toJson(request);
    }

    public void setCostRequest(SyncCostRequest costRequest) {
        this.costRequest = costRequest;
    }
}
